package aden.SifWar;

import aden.Generic.Gen2DPoint;

public class SifWarPlayerMgr
{
	
	private SifWarMain mMain;
	
	public SifWarMain GetMain() {return mMain;}
	private SifWarPlayer[] mPlayers;
	private int            mPlayerCount;
	private int mCurrent;
	
	public static final int Status_SLAVE = 0;
	public static final int Status_MASTER = 1;
	public static final int Status_OBSERVER = 2;
	public static final int Status_Undefined = 3;
	private int mStatus;
		
	public int GetStatus() {return mStatus;}
	
	public SifWarPlayerMgr(SifWarMain inMain)
	{
		mStatus = 1;
		mMain = inMain;
		mPlayerCount = 2;
		mPlayers = new SifWarPlayer[mPlayerCount];
		for (int i = 0;
			 i < mPlayerCount;
		     ++i)
		{
			mPlayers[i] = new SifWarPlayer(this);
		}
	}
	
	public boolean UpdateVisibility()
	{
		for (int i = 0;
				 i < mPlayerCount;
			     ++i)
			{
				mPlayers[i].UpdateVisibility();
			}
		
		return true;
	}
	
	public void ChangePlayer()
	{
		++mCurrent;
		if (mCurrent == mPlayerCount)
		{
			mCurrent = 0;
		}
	}
	public int GetPlayerCount() 
	{
		return mPlayerCount;
	}
	

	public SifWarPlayer GetCurrentPlayer() 
	{
		return mPlayers[mCurrent];
	}
	
	
	public int GetCurrent() 
	{
		return mCurrent;
	}
		
	public SifWarPlayer GetPlayer(int inIndice) 
	{
		return mPlayers[inIndice];
	}
	
	public SifWarUnit FindUnit(Gen2DPoint inPoint)
	{
		SifWarUnit theUnit = null;
		for (int i = 0;
				i < mPlayerCount && theUnit == null;
				++i)
		{
			theUnit = mPlayers[i].GetTile(inPoint.GetX(),inPoint.GetY()).GetUnit();
		}
		return theUnit;
	}

	public boolean ReceiveOrders() {
		
		// TODO a faire
		
		// on attend les ordres des joueurs online
		
		// fenetre affichant ceux qu'on attend, etc ...
		
		
		return true;
	}

	public boolean SendOrders() {
		// TODO Auto-generated method stub
		
		// fenetre affichant le status du serveur et des joueurs

		return true;
	}

	public boolean ReceiveResults() {

		// update du monde en parcourant les logs
		
		// update de l'affichage
		
		return true;
	}

}